package com.wzxy.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.wzxy.model.UserEntity;
import com.wzxy.service.IUserService;

@Controller
@RequestMapping("/user")
public class UserController {
	@Resource
	private IUserService userService;
	
	
	/**
	 * 接受页面穿来的学生对象 UserEntity
	 * Model 向页面传值
	 */
	@RequestMapping(value = "/login",method = RequestMethod.POST)
	public String login(UserEntity user,Model model){
		boolean result = userService.isExist(user);
		
		if(result==true){
			model.addAttribute("username", user.getUsername());
		return "index";
		}else{
			model.addAttribute("login_error", "帐号或密码错误，请重新输入"); //向页面传值
			return "login";
		}
	}
	
}
